home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mmdf / mmdf-IIb.43 / doc / dbmdatabase < prev    next >
Encoding:
Text File  |  1986-02-01  |  22.7 KB  |  652 lines

  1. .TL
  2. The MMDF Database
  3. .br
  4. (somewhat obsolete)
  5. .AU
  6. Steve Kille
  7. .AI
  8. Department of Computer Science
  9. University College London
  10. .NH
  11. Overview
  12. .PP
  13. This design specifies modifications to the database access procedures
  14. of the MMDF mail system.
  15. The changes are motivated by the expansion of the names database for the
  16. SRI environment.
  17. The major changes involve the reorganization of the database for more
  18. efficient random access methods that would reduce the processing
  19. inefficiencies of the sequential access of large databases.
  20. The changes take advantage of the database management dbm(3)[*]
  21. .FS
  22. [*] The notation dbm(3) refers to the documentation as found in the Unix
  23. Programmer's Manual, Vol. 1, e.g., the database documentation is in
  24. Section 3 under the title
  25. .B dbm.
  26. .FE
  27. libraries
  28. of V7 Unix.
  29.  
  30. .NH 1
  31. Scope of Changes
  32. .PP
  33. All changes are restricted to two modules of MMDF.
  34. One module is part of the
  35. .B submit
  36. process
  37. and the other module is shared by the
  38. .B submit,
  39. .B deliver,
  40. and
  41. .B channel
  42. processes.
  43. There are potential efficiencies that could be gained in other modules due
  44. to the use of the new design but these changes are left for a future effort.
  45. The include file
  46. .B ch.h
  47. is compacted by eliminating obsolete fields in the channel
  48. structures.
  49.  
  50. .NH 2
  51. Affected Modules
  52. .PP
  53. The two modules that are affected are
  54. .B ch_table.c
  55. and
  56. .B adr_submit.c.
  57. .B ch_table
  58. is completely rewritten to use the dbm(3) library.
  59. Two procedures are respecified because their functions have been altered.
  60. The remaining procedures are reimplemented.
  61. The procedure
  62. .B loc_alsrch
  63. in the module
  64. .B adr_submit.c
  65. is modified to remove references to and logic for the obsolete procedure
  66. .B ch_tseek
  67. and to add logic to use the procedure
  68. .B ch_tsetnum.
  69. .NH 2
  70. Interfaces
  71. .PP
  72. The interfaces to the public procedures of ch_table.c are preserved.
  73. The re-implemented procedures have the same names, accept the same
  74. arguments, and
  75. return the same results as the procedures they replace.
  76. The respecified procedures have different names and arguments to
  77. ensure that incompatible calls to the old procedures would be caught and
  78. prevented from improperly linking to the new procedures.
  79. Some of the re-implemented procedures have a boolean argument that indicates
  80. whether the search
  81. should start at the beginning of the file or where the pointer is currently
  82. located.
  83. The argument now indicates whether the partial ordering information stored
  84. in the database should be used to detect possible name circuits.
  85.  
  86. .NH 2
  87. Affected Procedures
  88. .PP
  89. Only one procedure,
  90. .B loc_alsrch,
  91. in the module
  92. .B adr_submit.c
  93. is modified.
  94. The modification is described above.
  95. All other procedures in this section are in the module
  96. .B ch_table.c.
  97. .SH
  98. ch_tblopen
  99. .IP
  100. This procedure is removed completely and
  101. its replacement,
  102. .B ch_tdbminit,
  103. is made completely internal to the module.
  104. It calls the
  105. .B dbminit
  106. procedure for the first database access
  107. to initialize the database.
  108.  
  109. .SH
  110. ch_tseek
  111. .IP
  112. This procedure is removed completely.
  113. It is replaced by the procedure
  114. .B ch_tsetseq
  115. which sets the minimum acceptable point for an entry to be in the partial
  116. ordering of the database.
  117. .SH
  118. ch_ttell
  119. .IP
  120. This is really a macro defined in the file
  121. .B ch.h.
  122. It is removed and the procedure
  123. .B ch_tgetseq
  124. is defined in its place to return the partial ordering of the most recently
  125. accessed entry in the database.
  126. .SH
  127. ch_h2adr
  128. .IP
  129. This procedure is rewritten internally to use the dbm(3) library.
  130. The argument
  131. .B first
  132. is redefined to be a flag to indicate whether partial ordering of the entries
  133. is to be enforced.
  134. All other aspects of the procedure remain the same.
  135. .SH
  136. ch_ad2first
  137. .IP
  138. This procedure is rewritten internally to use the dbm(3) library.
  139. The external interface for this procedure remains the same.
  140. .SH
  141. ch_h2first
  142. .IP
  143. This procedure is rewritten internally to use the dbm(3) library.
  144. The argument
  145. .B frst
  146. is redefined to be a flag to indicate whether partial ordering of the entries
  147. is to be enforced.
  148. All other aspects of the procedure remain the same.
  149. .SH
  150. ch_h2chan
  151. .IP
  152. This procedure is rewritten internally to use the dbm(3) library.
  153. The external interface for this procedure remains the same.
  154. .PP
  155. The procedures no longer access each other internally.
  156. They instead set up their own calls to the dbm(3) procedure
  157. .B fetch
  158. and process the returned data themselves.
  159. The linkages between data records is defined in the logic of the access
  160. procedures.
  161.  
  162. .NH 1
  163. Addressing Database Design
  164. .PP
  165. The support provided by the dbm(3) library consists of procedures to
  166. store and retrieve data items using arbitrary ascii strings as keys.
  167. Since no provision is made for accessing the internal representation of
  168. keys or data pointers, all linkages are maintained as ascii keys.
  169. The interpretation of a data item as a key for further searches of the
  170. database is therefore embedded in the MMDF access procedures.
  171. The subsections below define these relationships between data items and
  172. other keys.
  173.  
  174. .NH 2
  175. Database Internals
  176. .PP
  177. The sequential database is composed of lists of key and value pairs.
  178. Each list is a separate text file that is appropriate only in certain
  179. contexts.
  180. An address or name is either a mailbox or a host depending on whether it
  181. is in the file used for aliases or the file used for channel host addresses.
  182. The formats however are identical.
  183. .PP
  184. A data entry is composed of three components; the keyword that is used for
  185. access, a partial ordering number, and a list of one or more values
  186. separated by FS ('\\034') characters.
  187. See Figure 2 and Section 5.2.1 for the details and format of the entry.
  188.  
  189. .PP
  190. A value is composed of a channel code character followed by a printable
  191. ascii string.
  192. There are three basic types of values used in the data entries.
  193. They provide single, multiple, and indirect values for the keys.
  194. All of the types are transparent to the database procedures and are returned
  195. unmodified to the calling procedures for processing.
  196.  
  197. .IP Single 10
  198. This is the simplest form of database value.
  199. It is a single ascii string that is passed back to the address processor.
  200. The value can be the real name associated with an alias, a host name
  201. associated with a channel, or a host address associated with a host name.
  202.  
  203. .IP Multiple 10
  204. A multiple value is a comma ',' separated list of single values.
  205. All of the single values are associated simultaneously with the key.
  206. Such a value is used for small distribution lists or for aliasing a name
  207. to mailboxes for a user on different machines.
  208.  
  209. .IP Indirect 10
  210. The indirect value is an extension of the multiple value.
  211. A value that starts with a left angle bracket '<' character is treated
  212. as a filename (not including the '<') where a list of values may be found.
  213. Distribution lists are implemented with indirect values.
  214. The referred to file is not searched but is read sequentially for
  215. values that are then recursively processed against the database.
  216.  
  217. .PP
  218. Only one file is used in the dbm(3) library[*].
  219. .FS
  220. [*] There are really two files, one data file and one key hash file,
  221. but they are considered as one in this context since they are intimately
  222. connected in the dbm(3) library.
  223. .FE
  224. Identical keys that are in different lists in the sequential files are
  225. stored under one key in the random access database.
  226. The storing of identical keys is described in the next section.
  227.  
  228. .NH 3
  229. Partial Ordering Numbers
  230. .PP
  231. The ordering of entries in the sequential database is used by the sequential
  232. database to detect name circuits.
  233. The first two bytes of an entry datum are an unsigned 16 bit ordering number
  234. that indicates the partial ordering between any two entries in the database.
  235. The numbers are assigned by the database management program.
  236. Section 3.2 Name Circuit Prevention describes its use.
  237.  
  238. .NH 3
  239. Channel Encoding
  240. .PP
  241. The context information implied in the multiple files used for the sequential
  242. database must be preserved in the random access database.
  243. This context is preserved by prepending a code character to the value.
  244. This code is either the official name code or the code character
  245. assigned to a channel.
  246. The code is used both to check whether the value is valid
  247. for a particular channel and to map a name(host) to a channel.
  248. .PP
  249. Identical keys may be stored in more than one file in the sequential database.
  250. This feature is implemented in the random access database by concatenating
  251. the entries from the multiple files and separating them by the FS ('\\034')
  252. character.
  253. The first character of each entry in such a list is the code character for
  254. that entry.
  255. Note that the first character is a code only for these multiple entries and
  256. not for the multiple comma ',' separated values described above.
  257. The code character is stripped by the procedures and not returned.
  258. The sequential order of the entries implies the partial ordering imposed
  259. in the sequential database.
  260.  
  261. .NH 3
  262. Official Names
  263. .PP
  264. An official name is the primary identifier for a host.
  265. Other names are allowed but the official name is the only name that is
  266. universally known by all other hosts.
  267. Alternate or alias names are available but MMDF converts these names to
  268. the official name before the address is used in the system.
  269. .PP
  270. By convention, the key associated with the first occurrence of a value
  271. (address) in the sequential file is the official name.
  272. It may be found from an address by searching for the first occurrence of the
  273. address in the value field and returning the key as the official name.
  274. The official name is found from an alternate by first finding the alternate
  275. and then by taking its value (address) and searching for the its first
  276. occurrence.
  277.  
  278. .PP
  279. There are two entries stored in the database for an official name.
  280. One is a normal name-key with address-entry and the other is
  281. an address-key and name-entry.
  282. The name-entry has a code character of '='.
  283. An official name is recognized when the database is being built and the
  284. inverse of the entry is generated by exchanging key and entry and storing
  285. the result.
  286. The official name is also stored as the first entry of all other (alias)
  287. entries that have the same address as the official name.
  288. The official name is retrieved from a value (address) by retrieving
  289. the entry under the address key.
  290. It is retrieved from an alternate name by retrieving the entry with the
  291. alternate name keyword and then selecting the official name entry.
  292.  
  293. .NH 3
  294. Name List Redirection
  295. .PP
  296. Name list redirection is not part of the sequential search database
  297. procedures.
  298. The procedure
  299. .B alst_proc
  300. parses the value returned from reading the current address.
  301. The address line may either come from an input line or
  302. a database value due to the recursive
  303. logic of the address parsing procedures.
  304. The redirection is done on all addresses that start with the '<' character.
  305. This character is transparent to the database system and is considered part
  306. of the returned value.
  307. The partial ordering numbers are used by the database procedures to detect and
  308. reject name circuits generated when keywords in the indirect files do not
  309. map to out of order entries in the database.
  310. .NH 3
  311. Reserved Code Characters
  312. .PP
  313. The only reserved code character is '='.
  314. This character may not be used for channel codes because it is used to
  315. identify an official name.
  316. It should be considered to be the official name channel code character.
  317. The FS ('\\034') character is also reserved for use as the entry separator.
  318. All other characters are acceptable.
  319.  
  320. .NH 2
  321. Name Circuit Prevention
  322. .PP
  323. A name circuit exists when a name key is self referencing though an
  324. arbitrary number of name translations.
  325. Such a name would put the address checking procedures in an infinite loop.
  326. The sequential database defeats some cases of self reference by forcing
  327. the search of any one list at any one level to be one pass.
  328. This algorithm forces a partial ordering of all addresses;
  329. but it is only enforced for one file at a time.
  330. .PP
  331. The random access database contains an ordering number for each entry in the
  332. database that identifies the order in which the entries were stored in the
  333. database.
  334. This partial ordering of the
  335. entries prevents name circuits by forcing all translations to be
  336. forward references that would eventually terminate with the end of the list.
  337. The check for partial ordering is under the control of the argument to the
  338. the applicable procedures that controlled whether the sequential search
  339. started from the beginning of the file.
  340. The partial ordering is not enforced if the argument is TRUE to be compatible
  341. with the old procedures.
  342.  
  343. .NH 1
  344. Database Access Procedures
  345. .PP
  346. This section describes the algorithms used to implement the database with
  347. the dbm(3) package.
  348. These procedures replace those procedures of the same name in the file
  349. .B ch_table.c
  350.  
  351. .NH 2
  352. Access Initialization
  353. .PP
  354. The procedure
  355. .B ch_tblopen
  356. is removed and it is replaced by the procedure
  357. .B ch_tdbminit
  358. which is callable only by the procedures
  359. within the module.
  360. There is no argument list.
  361. An internal static flag is maintained by the procedure to
  362. record if the database file is initialized.
  363. During the course of this procedure it will call the dbm(3) procedure
  364. .B dbminit
  365. and set the flag so further calls to the procedure will not attempt to
  366. initialize the database again.
  367.  
  368. .NH 2
  369. Partial Ordering Control
  370. .PP
  371. The old procedure
  372. .B ch_tseek
  373. and the macro
  374. .B ch_ttell
  375. are deleted from the file along with all references to them.
  376. They are replaced by the procedures
  377. .B ch_tsetseq
  378. and
  379. .B ch_tgetseq
  380. which control the partial ordering in the database.
  381. .B ch_tgetseq
  382. returns the sequence number of the most recently accessed entry and
  383. .B ch_tsetseq
  384. changes the internal sequence number value to its argument.
  385. A sequence number is a value of type unsigned short.
  386.  
  387. .NH 2
  388. Database Record Access
  389. .PP
  390. All records in the database are accessed by the internal procedure
  391. .B ch_fetch.
  392. It correctly forms its string argument into a key for the dbm(3) procedure
  393. .B fetch
  394. and decomposes the returned datum into the partial ordering number and
  395. a vector of char pointers to the individual values.
  396. The number and the vector are stored in the data structure passed to the
  397. procedure.
  398. Success return is indicated by returning the pointer to the data structure
  399. and failure is indicated by a NULL pointer.
  400.  
  401. .NH 2
  402. Key to Value Access
  403. .PP
  404. This function is done by the procedure
  405. .B ch_h2adr.
  406. The 'name' parameter is passed to the internal procedure
  407. .B ch_fetch.
  408. The returned structure may have multiple entries because the same key may
  409. be used for more than one channel or alias list.
  410. The code character of each entry is checked against the code character
  411. stored in the channel structure and
  412. the entry that matches is returned in the pointer parameter 'buf' with its
  413. code character stripped off.
  414. TRUE is returned if a match was found and FALSE is returned if
  415. .B ch_fetch
  416. can not find the key or if the code character for the channel does not
  417. match an entry in the datum.
  418.  
  419. .NH 2
  420. Value to Primary Key Access
  421. .PP
  422. This function is performed by the procedure
  423. .B ch_ad2first.
  424. The parameter 'adrstr' is passed to the procedure
  425. .B ch_fetch
  426. as described above and the returned structure is scanned for an entry whose
  427. code character matches the official name code character '='.
  428. The result is returned via the pointer parameter 'buf'.
  429. TRUE is returned if a match was found and FALSE is returned if
  430. .B ch_fetch
  431. can not find the key or if there is no official name.
  432.  
  433. .NH 2
  434. Key to Primary Key Access
  435. .PP
  436. This function is performed by the procedure
  437. .B ch_h2first.
  438. The parameter 'str' is passed to the procedure
  439. .B ch_fetch
  440. and the returned structure is searched for an official name entry.
  441. The official name is returned via
  442. the pointer parameter 'buf'.
  443. TRUE is returned if a match was found and FALSE is returned if
  444. .B ch_fetch
  445. can not find the key or if there is no official name entry.
  446. The parameter 'str' is returned if no official name is found.
  447.  
  448. .NH 2
  449. Key to Any Channel Access
  450. .PP
  451. This function is performed by the procedure
  452. .B ch_h2chan.
  453. The parameter 'hostr' is passed to the procedure
  454. .B ch_fetch.
  455. The pointer parameter 'adrstr' is used to return either the official name
  456. if it is found or the parameter 'adrstr' if none is found.
  457. The procedure returns NOTOK if there is no official name.
  458. Each value except the official name in the entry is used in turn to find
  459. the first channel available for the key.
  460. The code character of the value is passed to the procedure
  461. .B ch_c2struct
  462. which will either return a channel pointer or the value NOTOK.
  463. If there is no channel to match any of the code characters then
  464. .B ch_h2chan
  465. also returns NOTOK.
  466. If the channel found by
  467. .B ch_c2struct
  468. is the local channel and local delivery is ok then the procedure returns OK.
  469. Otherwise, it returns the channel pointer.
  470.  
  471. .NH 1
  472. Database Management Program
  473. .PP
  474. The program
  475. .B dbmbuild
  476. generates the database from ascii files of the same format
  477. as the sequential database.
  478. It does not attempt to do updates to an existing database; rather, it
  479. regenerates the entire database each time and the resultant files are
  480. moved into place with other commands.
  481.  
  482. .NH 2
  483. Inputs
  484. .PP
  485. The input to the program is in the current sequential file format.
  486. The code character is passed to the program as a command line argument.
  487. A command line argument selects official name processing; the default
  488. action is no processing.
  489.  
  490. .KS
  491. .DS
  492. line ::= text eol
  493. text ::= comment | entry
  494. comment ::= '#' <any printable ascii string>
  495. entry ::= key sep value
  496. key ::= <lower case printable ascii string>
  497. sep ::= ':' | <space> | <tab>
  498. value ::= <printable ascii string with optional spaces or tabs>
  499. eol ::= '\e012'
  500. .ce
  501. Fig . 1, Input Line format
  502. .DE
  503. .KE
  504. .NH 2
  505. Outputs
  506. .PP
  507. The output file is generated into two files.
  508. The file\fI.dir\fP file contains a bitmap directory of the actual
  509. keys and values
  510. located in the file\fI.pag\fP file.
  511. The file is generated by the
  512. .B store
  513. procedure of the dbm(3) library.
  514. See the Unix Programmer's Manual, Vol 1, dbm(3x), for further details on
  515. the database library.
  516.  
  517. .NH 3
  518. Record Format
  519. .PP
  520. A record consists of a key and a datum.
  521. The key is an arbitrary ascii text string but for matching purposes
  522. it is all lower case with all extraneous white space compressed out.
  523. The datum is an arbitrary variable length byte string.
  524. The length is controlled by a count field.
  525. The subfields of the datum are defined below.
  526. There is no white space separating any of the fields.
  527. They are either defined by position and count or by the field separator
  528. (FS) character.
  529. .KS
  530. .DS
  531. datum ::= serial-number entry-list
  532. serial-number ::= <two bytes used as unsigned short>
  533. entry-list ::= entry
  534.          | entry-list FS entry
  535. entry ::= code-char value
  536. code-char ::= <printable ascii char matching channel char>
  537. value ::= <arbitrary compressed printable ascii string>
  538. FS ::= '\e034'
  539. .ce
  540. Fig. 2, Internal Record Format
  541. .DE
  542. .KE
  543.  
  544. .NH 2
  545. Algorithms
  546. .PP
  547. These algorithms convert a sequential database into the random access
  548. database suitable for the online MMDF.
  549.  
  550. .NH 3
  551. Partial Ordering Control
  552. .PP
  553. At the start of processing an input file the entry under the key
  554. "Local-Name" is retrieved and the serial number field is retained for
  555. further processing.
  556. If the entry is not found then the serial number is initialized to 1 and
  557. the key "Local-Name" is stored.
  558. The name is stored again at the end of processing with a datum containing
  559. the updated serial number.
  560. Any values stored under the key are preserved so that the key may be
  561. used to store other information in addition to the serial number.
  562. In future, this entry can be used to store the host's local name instead
  563. of the separate file currently used.
  564.  
  565.  
  566. .NH 3
  567. Channel Encoding
  568. .PP
  569. Channel code characters are passed to the program with the sequential
  570. data file.
  571. The code characters are retained by the program and prepended to values
  572. as they are stored in the database.
  573. There is currently one code character assigned for each channel in the
  574. system as well as the '=' character which identifies an official name.
  575.  
  576. .NH 3
  577. Identical Keys
  578. .PP
  579. Identical keys are allowed in the sequential database.
  580. They are implemented in the random database by concatenating the entries
  581. according to the record format in Fig 2.
  582. The key part of an input line is retrieved before it is stored into the
  583. database.
  584. The retrieved datum is used instead of an initialized empty datum
  585. whenever the retrieval returns a valid datum.
  586. The new entry is appended to the end along with its code character and
  587. separated from the rest of the retrieved entry by the FS character.
  588.  
  589. .NH 3
  590. Official Name Processing
  591. .PP
  592. An official name in the sequential database is the first name associated with
  593. a particular address.
  594. Official names are detected and marked in the random access database in a
  595. similar manner.
  596. Official names are entered into the database under the control of a command
  597. line argument; the default action is to not process official names.
  598. .PP
  599. As the sequential input file is read for entries to store in the database, the
  600. value, i.e., address, part is \fIfetch\fPed to see if it is present.
  601. If the
  602. .B fetch
  603. returns a valid pointer to an official name then it will be used to build
  604. the datum for the current input line.
  605. If the pointer is valid but the value is not an official name then
  606. the official name is appended using the format from Fig 2 and datum is
  607. stored back into the database.
  608. A NULL pointer indicates that the current entry is an official name.
  609. The value from the address part (from above) is used as a key and the key
  610. part of the current input line is used as the value for the new entry.
  611. The entry has a '=' code character and the value
  612. is 'canonicalized', i.e., the first character and the
  613. first character after a '-' are capitalized.
  614. This official name entry is always stored as the first value in the datum for
  615. all names, including itself, that refer to it.
  616. The string is stored in every datum already canonicalized in order to
  617. save processing time for MMDF.
  618. .NH 3
  619. Name Circuit Detection
  620. .PP
  621. A name circuit is exists if there is a valid key to the database that is
  622. equal to the value in the current input line that is not
  623. the inverse key of an official name.
  624. This can occur only if there was a previous entry in the database that
  625. had a key equal to the value of the current entry.
  626. The input line is stored as an additional value in the entry.
  627. (See Section 5.3.3).
  628. There is a change in the way name circuits are rejected by the database
  629. because the partial ordering for the entry remains the same.
  630. Any identical keys which would have been valid in the sequential database
  631. because they were positionally correct are no longer valid because they
  632. are, in effect, moved up to be just below (actually part of)
  633. the first, out of order key.
  634. This restriction prohibits certain obscure or clever alias list
  635. manipulations.
  636. .PP
  637. Forward references, i.e., the value field of a previous entry is equal to
  638. the key of the current entry, are allowed in the sequential database since
  639. the linkages will terminate at the end of file.
  640. These are allowed in the random access database too because the database
  641. procedures will check sequence numbers when requested by the calling
  642. procedure and reject all fetches that are not
  643. forward references thereby preventing the name circuit.
  644. .NH 2
  645. Error Processing
  646. .PP
  647. All system and database inconsistency errors are reported to the
  648. operator on the standard error output.
  649. All improperly formed entries
  650. are rejected.
  651.  
  652.